package com.gitee.wsl.ext.number

import kotlin.math.ceil
import kotlin.math.floor
import kotlin.math.roundToInt

/**
 * This value rounded to the nearest whole [Float].
 */
inline val Float.round: Float
    get() = roundToInt().toFloat()

/**
 * The largest whole [Float] smaller than or equal to this value.
 */
inline val Float.floor: Float
    get() = floor(this)

/**
 * The smallest whole [Float] greater than or equal to this value.
 */
inline val Float.ceil: Float
    get() = ceil(this)

fun Float.bound(min: Float, max: Float): Float =
    max.coerceAtMost(min.coerceAtLeast(this))

fun Int.bound(min: Int, max: Int): Int =
    max.coerceAtMost(min.coerceAtLeast(this))
